define([
'jquery',
'jquery.xml2json'
],
function($){
    function ResultObject(data, operation){
        this.data = $.xml2json(data)['Body'][operation+'Response'][operation+'Result'];
    }
   
    ResultObject.prototype.error = function(){
        if (typeof this.data.error != "undefined" && this.data.error != null) {
            return this.data.error.toString().split('error:')[1];
        } else {
            return null;
        }
    }

    ResultObject.prototype.result = function(){
        if (typeof this.data.result != "undefined" && this.data.result != null && this.data.result != "") {
            if (this.data.result.hasOwnProperty('xsi:type') && this.data.result['xsi:type'].indexOf('Array') > -1){
                for(var prop in this.data.result){
                    if(prop != "xsi:type" && prop != "__proto__"){
                        this.data.result[prop] = $.isArray(this.data.result[prop]) ? this.data.result[prop] : [this.data.result[prop]];
                    }
                }
            }
            return this.data.result;
        } else {
            return null;
        }
    }
    return ResultObject;     
});
